package com.ad.platform.api;


import com.ad.payload.dto.MerchantDto;
import com.ad.payload.dto.merchant.ItemDetailPageDto;
import com.ad.payload.model.IdDto;
import com.ad.payload.model.PageDto;
import com.ad.payload.model.PageView;
import com.ad.payload.vo.item.ItemImgVo;
import com.ad.payload.vo.merchant.ItemCategoryVo;
import com.ad.payload.vo.merchant.ItemCoverVo;
import com.ad.payload.vo.merchant.MerchantVo;
import com.ad.platform.service.IMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.ws.rs.POST;
import java.util.List;

/**
 * <p>
 * 商家记录 前端控制器
 * </p>
 *
 * @author gdx
 * @since 2021-03-25
 */
@RestController
@RequestMapping("/MerchantApi")
public class MerchantApi {

    @Autowired
    private IMerchantService iMerchantService;

    /**
     * 小程序首页查询商家（类目内部分商家列表查询）
     *
     * @param merchantDto
     * */
    @PostMapping("/client/noAuth/listPageMerchantForIndex")
    public PageView<MerchantVo> listPageMerchantForIndex(@RequestBody MerchantDto merchantDto){
        return iMerchantService.listPageMerchantForIndex(merchantDto);
    }


    /**
     * 查询商家信息
     *
     * @param idDto
     * */
    @PostMapping("/client/noAuth/queryMerchantDetail")
    public MerchantVo queryMerchantDetail(@RequestBody @Valid IdDto idDto){
        MerchantVo merchantVo = iMerchantService.queryMerchantDetail(idDto);
        return merchantVo;
    }


    /**
     * 查询当前商家的产品分类
     *
     * @param idDto
     * */
    @PostMapping("/client/noAuth/queryMerchantCategory")
    public List<ItemCategoryVo> queryMerchantCategory(@RequestBody @Valid IdDto idDto){
        List<ItemCategoryVo> itemCategoryVos = iMerchantService.queryMerchantCategory(idDto);
        return itemCategoryVos;
    }



    /**
     * 根据产品分类ID产品分页列表
     *
     * @param itemDetailPageDto
     * */
    @PostMapping("/client/noAuth/pageListItemDetail")
    public PageView<ItemCoverVo> pageListItemDetail(@RequestBody @Valid ItemDetailPageDto itemDetailPageDto){
        PageView<ItemCoverVo> itemCoverVoPageView = iMerchantService.pageListItemDetail(itemDetailPageDto);
        return itemCoverVoPageView;
    }


    /**
     * 查询商品的封面图，详情图
     *
     * @param idDto
     * */
    @PostMapping("/client/noAuth/queryItemImg")
    public ItemImgVo queryItemImg(@RequestBody @Valid IdDto idDto){
        ItemImgVo imgVo = iMerchantService.queryItemImg(idDto);
        return imgVo;
    }

}

